import matplotlib.pyplot as plt
import numpy as np

# 中文显示
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei','DV Sans']
plt.rcParams['axes.unicode_minus'] = False

def local_boundedness():
    x0 = 1
    delta = 0.5
    x = np.linspace(x0 - delta, x0 + delta, 100)
    f_x = np.sin(x) * np.exp(x)  # 复杂但连续的函数
    
    plt.figure(figsize=(10, 6))
    plt.plot(x, f_x, 'b-', linewidth=2, label='f(x) = sin(x) * exp(x)')
    plt.axvline(x=x0-delta, color='r', linestyle='--', alpha=0.7)
    plt.axvline(x=x0+delta, color='r', linestyle='--', alpha=0.7)
    
    # 计算上下界
    upper_bound = max(f_x)
    lower_bound = min(f_x)
    
    plt.axhline(y=upper_bound, color='g', linestyle=':', label=f'上界: {upper_bound:.2f}')
    plt.axhline(y=lower_bound, color='g', linestyle=':', label=f'下界: {lower_bound:.2f}')
    
    plt.title('局部有界性演示')
    plt.xlabel('x'); plt.ylabel('f(x)')
    plt.legend(); plt.grid(True, alpha=0.3)
    plt.show()

local_boundedness()